package com.flink.datastreamapi.source;


import org.apache.flink.api.common.eventtime.WatermarkStrategy;
import org.apache.flink.connector.file.src.FileSource;
import org.apache.flink.connector.file.src.reader.TextLineInputFormat;
import org.apache.flink.core.fs.Path;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

public class FileSourceDemo {
    public static void main(String[] args) throws Exception {
        //获取执行环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
       // env.setParallelism(1);
        //读取数据源--文件
        //env.readTextFile()
        FileSource<String> fileSource = FileSource.forRecordStreamFormat(
                new TextLineInputFormat(),
                new Path("input/words.txt")
                )
                .build();

        DataStreamSource<String> dataSource = env.fromSource(
                fileSource,
                WatermarkStrategy.noWatermarks(),
                "file-source");


        //输出
        dataSource.print();

        //执行
        env.execute();
    }
}
